package com.zz.bid.mapper;

import com.zz.bid.pojo.query.BidQuery;
import com.zz.bid.pojo.to.BidDesc;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author chenkehan created at 2020/4/4 6:26 下午
 */
@Mapper
public interface BidMapper {

    @Insert("insert into op_bid(name,inCharge,hasTech,department,openDate,bidStatus,enabled,lastUpdateUser,lastUpdateTime,bidCharge,scale,openBy,auditor,refundInfo,winBid,createdBy,createdDate) "
            + "values(#{bidDesc.name},#{bidDesc.inCharge},#{bidDesc.hasTech},#{bidDesc.department},#{bidDesc.openDate},#{bidDesc.bidStatus},1,#{bidDesc.lastUpdateUser},#{bidDesc.lastUpdateTime},#{bidDesc.bidCharge},#{bidDesc.scale},#{bidDesc.openBy},#{bidDesc.auditor},#{bidDesc.refundInfo},#{bidDesc.winBid},#{bidDesc.createdBy},#{bidDesc.createdDate})")
    @Options(useGeneratedKeys = true, keyProperty = "bidDesc.id", keyColumn = "id")
    void create(@Param("bidDesc") BidDesc bidDesc);

    @Update("update op_bid set name=#{bidDesc.name},inCharge=#{bidDesc.inCharge},hasTech=#{bidDesc.hasTech},department=#{bidDesc.department},openDate=#{bidDesc.openDate},bidStatus=#{bidDesc.bidStatus},auditor = #{bidDesc.auditor}, bidCharge = #{bidDesc.bidCharge}, scale = #{bidDesc.scale}, openBy = #{bidDesc.openBy}, winBid = #{bidDesc.winBid}, refundInfo = #{bidDesc.refundInfo}, createdBy = #{bidDesc.createdBy} "
            + "where id = #{bidDesc.id} and enabled = 1")
    void update(@Param("bidDesc") BidDesc bidDesc);

    List<BidDesc> listBid(@Param("bidQuery") BidQuery bidQuery);

    @Select("select name,inCharge,hasTech,department,openDate,bidStatus,auditor,refundInfo,bidCharge,scale,openBy,createdBy from op_bid where enabled = 1 and id=#{bidId}")
    BidDesc getBidDesc(@Param("bidId") int bidId);

    @Update("update op_bid set enabled = 0 where id = #{bidId}")
    void deleteBid(@Param("bidId") int bidId);
}
